package com.njsoft.bodyawakening.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * 分割线
 */
public class HDividerDecoration extends RecyclerView.ItemDecoration {

    private int dividerHeight;
    private Paint dividerPaint;
    private String TAG = "Divide-->";

    public HDividerDecoration(Context context, int color, int dp) {
        dividerPaint = new Paint();
        dividerPaint.setColor(context.getResources().getColor(color));
        dividerHeight = context.getResources().getDimensionPixelSize(dp);
    }


    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int childCount = parent.getChildCount();

            //这里直接硬编码为1px
        if(parent.getChildAdapterPosition(view)==0){
            outRect.left=dividerHeight;
        }
        outRect.right = dividerHeight;
        outRect.top = dividerHeight;
        outRect.bottom = dividerHeight;

    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//        int childCount = parent.getChildCount();
//        int bottom = parent.getPaddingBottom();
//        int top = parent.getHeight() + parent.getPaddingTop();
//
//        for (int i = 0; i < childCount; i++) {
//            View view = parent.getChildAt(i);
//            float left = view.getLeft();
//            float right = view.getRight() + dividerHeight;
//            L.v(TAG, "left:" + left + " top:" + top + " right:" + right + " bottom:" + bottom);
//
//            c.drawRect(left, top, right, bottom, dividerPaint);
//        }
    }
}
